Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Do not fail on empty choices response#93

Open
vnlitvinov wants to merge 1 commit intoray-project:mainfrom
vnlitvinov:fix-division-by-zero
Open

Do not fail on empty choices response#93
vnlitvinov wants to merge 1 commit intoray-project:mainfrom
vnlitvinov:fix-division-by-zero

Conversation

@vnlitvinov
Copy link

This fixes #55 for a case when OpenAI-compatible server sends empty choices (according to OpenAI docs, this could happen for last chunk if certain stream_options are set).

This fixes ray-project#55

Signed-off-by: Vasily Litvinov <vasilii@io.net>
generated_text += delta["content"]

if data["choices"]:
delta = data["choices"][0]["delta"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, sometimes I just get choices: [{}] from openai.

                        delta = data["choices"][0].get("delta", {})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Divide by zero: request_metrics[common_metrics.REQ_OUTPUT_THROUGHPUT] = num_output_tokens / request_metrics[common_metrics.E2E_LAT]

2 participants